HAL ADC control function migration ¶
This section provides information about the HAL ADC control function migration.
HAL ADC configure channel ¶
Function Description ¶
The
HAL_ADC_ConfigChannel
function configures the specified ADC channel according to the
parameters specified in the
ADC_ChannelConfTypeDef
structure. This function is used to set
up the ADC channel for conversion, including the selection of the channel, the rank in the regular group,
the sampling time, and other parameters.
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function name |
HAL_ADC_ConfigChannel |
Function split into:
|
|
Parameters |
|
|
|
Return Values |
HAL status |
HAL_INVALID_PARAM, HAL_ERROR, HAL_OK |
Example Usage ¶
|
HAL1 |
HAL2 |
|---|---|
ADC_ChannelConfTypeDef sConfig;
/* Configure ADCx regular channel on rank 1 */
sConfig.Channel = ADC_CHANNEL_8;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.OffsetNumber = ADC_OFFSET_1;
sConfig.Offset = 0;
sConfig.OffsetSaturation = DISABLE;
sConfig.OffsetSign = ADC_OFFSET_SIGN_NEGATIVE;
HAL_ADC_ConfigChannel(&hadc, &sConfig);
|
hal_adc_channel_config_t adc_channel_config;
hal_adc_offset_config_t adc_offset_config;
adc_channel_config.group = HAL_ADC_GROUP_INJECTED;
adc_channel_config.sequencer_rank = 1;
adc_channel_config.input_mode = HAL_ADC_IN_SINGLE_ENDED;
adc_channel_config.sampling_time = HAL_ADC_SAMPLING_TIME_3CYCLES;
HAL_ADC_SetConfigChannel(hadc, HAL_ADC_CHANNEL_8, &adc_channel_config);
adc_offset_config.channel = HAL_ADC_CHANNEL_8;
adc_offset_config.level = 0;
adc_offset_config.sign = LL_ADC_OFFSET_SIGN_NEGATIVE;
adc_offset_config.saturation_signed = HAL_ADC_OFFSET_SAT_SIGNED_DISABLE;
adc_offset_config.saturation_unsigned = HAL_ADC_OFFSET_SAT_UNSIGNED_DISABLE;
HAL_ADC_SetConfigOffset(&hadc1, HAL_ADC_OFFSET_1, &adc_offset_config);
|
Related concepts: Unitary configuration APIs
HAL ADC analog watchdog configuration ¶
Function Description ¶
This function configures the analog watchdog (AWD) feature of the ADC. The AWD feature enables the ADC to monitor converted values and generate an interrupt when the value exceeds a specified range.
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function name |
HAL_ADC_AnalogWDGConfig |
HAL_ADC_SetConfigAnalogWD |
|
Parameters |
|
|
|
Return Values |
HAL status |
HAL_INVALID_PARAM, HAL_ERROR, HAL_OK |
Example Usage ¶
|
HAL1 |
HAL2 |
|---|---|
ADC_AnalogWDGConfTypeDef AnalogWDGConfig;
AnalogWDGConfig.WatchdogNumber = ADC_ANALOGWATCHDOG_2;
AnalogWDGConfig.WatchdogMode = ADC_ANALOGWATCHDOG_ALL_REGINJEC;
AnalogWDGConfig.Channel = ADC_CHANNEL_1;
AnalogWDGConfig.ITMode = ENABLE;
AnalogWDGConfig.HighThreshold = 0xFFF;
AnalogWDGConfig.LowThreshold = 0x000;
AnalogWDGConfig.FilteringConfig = ADC_AWD_FILTERING_NONE;
HAL_ADC_AnalogWDGConfig(&hadc1, &AnalogWDGConfig);
|
hal_adc_awd_config_t adc_awd_config;
adc_awd_config.channel = HAL_ADC_CHANNEL_1;
adc_awd_config.group = HAL_ADC_GROUP_REGULAR_INJECTED;
adc_awd_config.filtering = HAL_ADC_AWD_FILTERING_NONE;
adc_awd_config.threshold_low = 0xFFF;
adc_awd_config.threshold_high = 0x000;
HAL_ADC_SetConfigAnalogWD(hal_handle,
HAL_ADC_AWD_2,
&adc_awd_config);
|
Related concepts: Unitary configuration APIs
HAL ADCEx injected configuration channel ¶
Function Description ¶
This function configures a specific channel for injected conversions in the ADC. Injected conversions are typically used for high-priority or time-critical measurements.
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function name |
HAL_ADCEx_InjectedConfigChannel |
Function split into:
|
|
Parameters |
|
|
|
Return Values |
HAL status |
HAL_INVALID_PARAM, HAL_ERROR, HAL_OK |
Example Usage ¶
|
HAL1 |
HAL2 |
|---|---|
ADC_InjectionConfTypeDef sConfigInjected;
/* Configure ADCx injected channel on rank 1 */
sConfigInjected.InjectedChannel = ADC_CHANNEL_7;
sConfigInjected.InjectedRank = ADC_INJECTED_RANK_1;
sConfigInjected.InjectedSamplingTime = ADC_SAMPLETIME_3CYCLES;
sConfigInjected.InjectedSingleDiff = ADC_SINGLE_ENDED;
sConfigInjected.InjectedOffsetNumber = HAL_ADC_OFFSET_1;
sConfigInjected.InjectedOffsetSaturation = DISABLE;
sConfigInjected.InjectedOffsetSign = ADC_OFFSET_SIGN_POSITIVE;
sConfigInjected.InjectedOffset = 0;
sConfigInjected.InjectedNbrOfConversion = 4;
sConfigInjected.InjectedDiscontinuousConvMode = DISABLE;
sConfigInjected.AutoInjectedConv = DISABLE;
sConfigInjected.QueueInjectedContext = DISABLE;
sConfigInjected.ExternalTrigInjecConvEdge = ADC_EXTERNALTRIGINJECCONV_EDGE_NONE;
sConfigInjected.ExternalTrigInjecConv = ADC_EXTERNALTRIGINJECCONV_EXT_IT15;
HAL_ADCEx_InjectedConfigChannel(&hadc, &sConfigInjected);
|
hal_adc_inj_config_t adc_inj_config;
hal_adc_channel_config_t adc_channel_config;
hal_adc_ovs_config_t adc_ovs_config;
hal_adc_offset_config_t adc_offset_config;
adc_inj_config.trigger_src = HAL_ADC_INJ_TRIG_EXTI15;
adc_inj_config.trigger_edge = HAL_ADC_INJ_TRIG_EDGE_NONE;
adc_inj_config.sequencer_length = 4;
adc_inj_config.sequencer_discont = HAL_ADC_REG_SEQ_DISCONT_DISABLE;
HAL_ADC_INJ_SetConfig(hadc, &adc_inj_config);
adc_channel_config.group = HAL_ADC_GROUP_INJECTED;
adc_channel_config.sequencer_rank = 1;
adc_channel_config.input_mode = HAL_ADC_IN_SINGLE_ENDED;
adc_channel_config.sampling_time = HAL_ADC_SAMPLING_TIME_3CYCLES;
HAL_ADC_SetConfigChannel(hadc, HAL_ADC_CHANNEL_7, &adc_channel_config);
adc_offset_config.channel = HAL_ADC_CHANNEL_7;
adc_offset_config.level = 0;
adc_offset_config.sign = LL_ADC_OFFSET_SIGN_POSITIVE;
adc_offset_config.saturation_signed = HAL_ADC_OFFSET_SAT_UNSIGNED_DISABLE;
adc_offset_config.saturation_unsigned = HAL_ADC_OFFSET_SAT_UNSIGNED_DISABLE;
HAL_ADC_SetConfigOffset(&hadc1, HAL_ADC_OFFSET_1, &adc_offset_config);
|
Related concepts:
HAL ADCEx multimode configuration channel ¶
Function Description ¶
This function configures the multimode settings for ADCs. Multimode allows multiple ADCs to work together to increase the sampling rate or resolution.
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function name |
HAL_ADCEx_MultiModeConfigChannel |
HAL_ADC_MM_SetConfig |
|
Parameters |
|
|
|
Return Values |
HAL status |
HAL_INVALID_PARAM, HAL_ERROR, HAL_OK |
Example Usage ¶
|
HAL1 |
HAL2 |
|---|---|
ADC_MultiModeTypeDef MultiModeConfig;
/* Configure multimode mode of ADC masters: ADC1 and ADC3 */
MultiModeConfig.Mode = ADC_MODE_INDEPENDENT;
MultiModeConfig.DMAAccessMode = ADC_DMAACCESSMODE_DISABLED;
MultiModeConfig.TwoSamplingDelay = ADC_TWOSAMPLINGDELAY_5CYCLES;
HAL_ADCEx_MultiModeConfigChannel(&hadc, &MultiModeConfig);
|
hal_adc_mm_config_t adc_mm_config;
/* ADC multimode config */
adc_mm_config.mode = HAL_ADC_MM_INDEPENDENT;
adc_mm_config.reg_data_format = HAL_ADC_MM_REG_DATA_EACH_ADC;
#if defined (USE_HAL_ADC_DMA) && (USE_HAL_ADC_DMA == 1)
adc_mm_config.reg_data_transfer_packing = (hal_adc_mm_reg_data_transfer_pack_t)0xFFFFFFFF;
#endif /* USE_HAL_ADC_DMA */
adc_mm_config.interl_delay = HAL_ADC_MM_INTERL_DELAY_5CYCLES;
hal_status |= HAL_ADC_MM_SetConfig(hal_handle_master, &adc_mm_config);
|
Related concepts: Merge HAL extension files with common ones and remove the EX prefix from APIs.
HAL ADCEx disable voltage regulator ¶
Function Description ¶
This function disables the internal ADC voltage regulator.
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function name |
HAL_ADCEx_DisableVoltageRegulator |
Removed |
Note
To disable the voltage regulator in HAL2, use the
LL_ADC_DisableInternalRegulator()
LL function.
Related concepts: Merge HAL extension files with common ones and remove the EX prefix from APIs.
HAL ADCEx enter ADC deep power down mode ¶
Function Description ¶
This function is used to enter the ADC deep-power-down mode.
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function name |
HAL_ADCEx_EnterADCDeepPowerDownMode |
Removed |
Note
To put an ADC instance in deep-power-down state in HAL2, use the
LL_ADC_EnableDeepPowerDown()
LL function.
Related concepts: Merge HAL extension files with common ones and remove the EX prefix from APIs.
HAL ADCEx enable injected queue ¶
Function Description ¶
This function is used to enable the injected queue.
|
HAL1 |
HAL2 |
|---|---|
|
HAL_ADCEx_EnableInjectedQueue |
Removed |
Related concepts: Merge HAL extension files with common ones and remove the EX prefix from APIs.
HAL ADCEx disable injected queue ¶
Function Description ¶
This function is used to disable the injected queue.
|
HAL1 |
HAL2 |
|---|---|
|
HAL_ADCEx_DisableInjectedQueue |
Removed |
Note
To enable/disable the injected queue in HAL2, use the
LL_ADC_INJ_SetQueueMode()
LL function.
Related concepts: Merge HAL extension files with common ones and remove the EX prefix from APIs.